import axios from 'axios'
import store from '../store/index'
axios.defaults.baseURL = "api"

export const $post = (url, params) => {
  return axios.post(`${url}`, params).then(res => res)
}

export const $get = (url, params) => {
  return axios.get(`${url}`, { params: params }).then(res => res)
}
axios.defaults.baseURL = "/api"
//添加请求拦截器
axios.interceptors.request.use(
  config =>{
    if(store.state.token){
      config.headers.common['token'] =store.state.token
    }
    return config;
  },
  error =>{
    //对请求错误做什么
    return Promise.reject(error);
  }
)
// 响应拦截
axios.interceptors.response.use(
  response =>{
    return response;
  },
  error =>{
    console.log(error)
  }
)
